package com.abigdreamer.im.server.ui;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;

import com.abigdreamer.im.server.ui.desktop.DeskTopConfig;
import com.abigdreamer.im.server.ui.desktop.ItemConfig;

public class PropetryTree extends JTree implements MouseListener {

	private static DeskTopConfig deskTopConfig;
	private static PropetryTree instance;
	public static PropetryTree getInstance(DeskTopConfig config) {
		deskTopConfig=config;
		if(instance==null){
			instance=new PropetryTree(config);
		}
		return instance;
	}
	
	public void refresh(){
		initTree();
		this.repaint();
	}
	private PropetryTree(DeskTopConfig config){
		this.deskTopConfig=config;
		initTree();
	}
	
	private void initTree(){
		DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode();
		rootNode.setUserObject("服务器");
		for(ItemConfig config:deskTopConfig.getItemList()){
			DefaultMutableTreeNode newNode = new DefaultMutableTreeNode();
			newNode.setUserObject(config.getItemText());
			rootNode.add(newNode);
		}
		DefaultTreeModel treeModel = new DefaultTreeModel(rootNode);
		this.setModel(treeModel);

	}
	public void mouseClicked(MouseEvent e) {
		
	}

	public void mouseEntered(MouseEvent e) {
		
	}

	public void mouseExited(MouseEvent e) {
		
	}

	public void mousePressed(MouseEvent e) {
		
	}

	public void mouseReleased(MouseEvent e) {
		
	}



}
